
**APPENDIX TABLE 6 : Bounds**

local mht = 1
log using "$out\OA-TableA6-Pvals", text replace
log off

*This code runs upper and lower bounds for male business outcomes to control for
*higher attrition amongst males in treatment group. The used dataset already has
*the bounds created. So only run PART 2 of this code.*

use "$data\business_visit.dta", clear

*PART 1: CREATING BOUNDS
*The following codes will generate two samples that will control for the higher
*attrition amongst males in trratment compared to control. So we create two 
*sample definitions by dropping the bottom x% of observations amongst male 
*treated members in the followup and another by dropping top x% of observations
*amongst male treated members in follow up.*
local y " bus_fixed all_months_operate  purchase_on_credit record_sale_last_month record_money_taken   number_workers log_good_month log_average_month log_bad_month   biz_assets_pca_m global_operation_outcomes2   index_busappearance  investmarketing bus_open_to_public secured_buyer_m   record_practice lognov08sale logprofit_revised   global_practice_outcomes global_monetary_outcomes"

foreach x in `y' {
	egen maletreat=group(female EDT_treat) if EDT_treat==1 & female==0 & post==1
	sort `x' maletreat
	gen temp=_n if  EDT_treat==1 & female==0 & post==1
	egen `x'nsid=group(maletreat temp) if  EDT_treat==1 & female==0 & post==1
	gen `x'_sl=1
	replace `x'_sl=. if  `x'nsid<=32
	lab var `x'_sl "a new sample that sets the lower x% of observations to missing"
	gen `x'_sh=1
	replace `x'_sh=. if `x'nsid>542 & !mi(`x'nsid)
	lab var `x'_sh "a new sample that sets the top x% of observations to missing"
	drop maletreat temp `x'nsid
}

*PART 2: RUNNING BOUNDED BUSINESS OUTCOMES*

*On the Excel, Section A corresponds to the middle column, Section B  the right
*one (upper bound) and Section C the left one (lower bound). Each section is 
*divided in (diff in diff) and (1-dif) to run variables for which we have values
*in baseline + follow up and only follow up respectively.

*************************************
****Unadjusted Treatment Effect******
*************************************

*diff in diff*
local xvars "EDT_treat d_lleligible fudummy*"
local yvars "bus_fixed all_months_operate purchase_on_credit record_sale_last_month record_money_taken log_good_month log_average_month log_bad_month"

est clear
local j =1
foreach y in `yvars' {
	log on
	reg `y'_fu `y'_bl1 `xvars' if (bus_basline==1) & female==0, cl(co_code)
	log off
	estimates store `y'_fu
	sum `y'_fu if (post==0 | bus_basline==1) & female==0
	estadd scalar mean_y=r(mean)
	local j = `j'+1
}

estout * using "$out/OA-TableA6-Unadj1.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear

if `mht' > 0 {
	foreach y in `yvars' {
		reg `y'_fu `y'_bl1 EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0, cl(co_code)
		predict xbhat, xb
		replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
		gen `y'_ur = `y'_fu - xbhat if (bus_basline==1) & female==0
		drop xbhat
	}
}

*1 diff*
local xvars "EDT_treat d_lleligible fudummy*"
local yvars "record_practice global_practice_outcomes index_busappearance  investmarketing bus_open_to_public secured_buyer_m biz_assets_pca_m global_operation_outcomes2  lognov08sale logprofit_revised global_monetary_outcomes"

est clear
local j =1
foreach y in `yvars' {
	log on
	reg `y' `xvars' if (bus_basline==1)& female==0 , cl(co_code)
	log off
	estimates store `y'
	sum `y' if (post==0 | bus_basline==1) & female==0
	estadd scalar mean_y=r(mean)
	local j = `j'+1
}

estout * using "$out/OA-TableA6-Unadj2.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear
local yvars2 "index_busappearance  investmarketing bus_open_to_public secured_buyer_m  biz_assets_pca_m record_practice  lognov08sale logprofit_revised "

if `mht' > 0 {
	foreach y in `yvars2' {
		reg `y' EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0, cl(co_code)
		predict xbhat, xb
		replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
		gen `y'_ur = `y' - xbhat if (bus_basline==1) & female==0
		drop xbhat
	}
	log on
	mhtexp purchase_on_credit_ur record_sale_last_month_ur record_money_taken_ur record_practice_ur, treatment(EDT_treat) 
	mhtexp bus_fixed_ur all_months_operate_ur index_busappearance_ur investmarketing_ur bus_open_to_public_ur secured_buyer_m_ur biz_assets_pca_m_ur, treatment(EDT_treat) 
	mhtexp log_good_month_ur log_average_month_ur log_bad_month_ur lognov08sale_ur logprofit_revised_ur, treatment(EDT_treat) 
	log off
}

***B. BOUNDED REGRESSIONS***

log on
*********************
****Upper Bound******
*********************
log off


*male with sample restricted by dropping lower x% observations* with controls*
*diff-in-diff*

local xvars "EDT_treat d_lleligible fudummy*"
local yvars "bus_fixed all_months_operate purchase_on_credit record_sale_last_month record_money_taken log_good_month log_average_month log_bad_month" 

est clear
local j =1
foreach y in `yvars' {
	log on
	reg `y'_fu `y'_bl1 `xvars' if (bus_basline==1) & female==0 & `y'_sl==1, cl(co_code)
	log off
	estimates store `y'
	sum `y'_fu if (post==0|bus_basline==1) & female==0 
	estadd scalar mean_y=r(mean)
	local j = `j'+1
}

estout * using "$out/OA-TableA6-UB1.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear

if `mht' > 0 {
	foreach y in `yvars' {
		reg `y'_fu  `y'_bl1 EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0 & `y'_sl==1, cl(co_code)
		predict xbhat, xb
		replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
		gen `y'_hr = `y' - xbhat if (bus_basline==1) & female==0 & `y'_sl==1
		drop xbhat
	}
}

*1-diff*
local xvars "EDT_treat d_lleligible female fudummy*"
local yvars "record_practice global_practice_outcomes index_busappearance  investmarketing bus_open_to_public secured_buyer_m biz_assets_pca_m global_operation_outcomes2  lognov08sale logprofit_revised global_monetary_outcomes"

est clear
local j =1
foreach y in `yvars' {
	log on
	reg `y' `xvars' if (bus_basline==1) & female==0 & `y'_sl==1, cl(co_code)
	log off
	estimates store `y'
	sum `y' if (post==0|bus_basline==1) & female==0 
	estadd scalar mean_y=r(mean)
	local j = `j'+1
}

estout * using "$out/OA-TableA6-UB2.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear

local yvars2 "index_busappearance  investmarketing bus_open_to_public secured_buyer_m  biz_assets_pca_m record_practice  lognov08sale logprofit_revised "

if `mht' > 0 {
	foreach y in `yvars2' {
		reg `y' EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0 & `y'_sl==1, cl(co_code)
		predict xbhat, xb
		replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
		gen `y'_hr = `y' - xbhat if (bus_basline==1) & female==0 & `y'_sl==1
		drop xbhat
	}
	log on
	mhtexp purchase_on_credit_hr record_sale_last_month_hr record_money_taken_hr record_practice_hr, treatment(EDT_treat)
	mhtexp bus_fixed_hr all_months_operate_hr index_busappearance_hr investmarketing_hr bus_open_to_public_hr secured_buyer_m_hr biz_assets_pca_m_hr, treatment(EDT_treat) 
	mhtexp log_good_month_hr log_average_month_hr log_bad_month_hr lognov08sale_hr logprofit_revised_hr, treatment(EDT_treat) 
	log off
}

log on
*********************
****Lower Bound******
*********************
log off

*male with sample restricted by dropping higher x% observations with controls*
local xvars "EDT_treat d_lleligible female fudummy*"
local yvars "bus_fixed all_months_operate purchase_on_credit record_sale_last_month record_money_taken log_good_month log_average_month log_bad_month"
 
*diff-in-diff*
est clear
local j =1
foreach y in `yvars' {
log on
reg `y'_fu `y'_bl1 `xvars' if (bus_basline==1) & female==0 & `y'_sh==1, cl(co_code)
log off
estimates store `y'
sum `y' if (post==0|bus_basline==1) & female==0 
estadd scalar mean_y=r(mean)
local j = `j'+1
}
estout * using "$out/OA-TableA6-LB1.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear

if `mht' > 0 {
foreach y in `yvars' {
	reg `y'_fu  `y'_bl1 EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0 & `y'_sh==1, cl(co_code)
	predict xbhat, xb
	replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
	gen `y'_lr = `y' - xbhat if (bus_basline==1) & female==0 & `y'_sh==1
	drop xbhat
}
}

set more off

local xvars "EDT_treat d_lleligible female fudummy*"
local yvars "record_practice global_practice_outcomes index_busappearance  investmarketing bus_open_to_public secured_buyer_m biz_assets_pca_m global_operation_outcomes2  lognov08sale logprofit_revised global_monetary_outcomes"
local yvars2 "index_busappearance  investmarketing bus_open_to_public secured_buyer_m  biz_assets_pca_m record_practice  lognov08sale logprofit_revised "

*1-diff*
est clear
local j =1
foreach y in `yvars' {
	log on
	reg `y' `xvars' if (bus_basline==1) & female==0 & `y'_sh==1, cl(co_code)
	log off
	estimates store `y'
	sum `y' if (post==0|bus_basline==1) & female==0 
	estadd scalar mean_y=r(mean)
	local j = `j'+1
}

estout * using "$out/OA-TableA6-LB2.xls", cells("b(star fmt(3))" se(par(`"="("' `")""'))) starlevels(* 0.10 ** 0.05 *** 0.01) stats(mean_y N r2, fmt(2 0 2) labels("mean dependent variable" "N.obs" "R-Sq")) replace
estimates clear

if `mht' > 0 {
	foreach y in `yvars2' {
		reg `y' EDT_treat d_lleligible fudummy* if (bus_basline==1) & female==0 & `y'_sh==1, cl(co_code)
		predict xbhat, xb
		replace xbhat = xbhat - _b[EDT_treat]*EDT_treat 
		gen `y'_lr = `y' - xbhat if (bus_basline==1) & female==0 & `y'_sh==1
		drop xbhat
	}
	log on
	mhtexp purchase_on_credit_lr record_sale_last_month_lr record_money_taken_lr record_practice_lr, treatment(EDT_treat) 
	mhtexp bus_fixed_lr all_months_operate_lr index_busappearance_lr investmarketing_lr bus_open_to_public_lr secured_buyer_m_lr biz_assets_pca_m_lr, treatment(EDT_treat) 
	mhtexp log_good_month_lr log_average_month_lr log_bad_month_lr lognov08sale_lr logprofit_revised_lr, treatment(EDT_treat) 
}

log close

